const { body, param } = require('express-validator');

exports.addArticleValidator = [
    body('title')
        .notEmpty().withMessage('title不能为空')
        .isLength({ min: 1, max: 255 }).withMessage('title长度必须在1-255之间'),
    body('content')
        .notEmpty().withMessage('content不能为空')
        .isLength({ min: 1, max: 2048 }).withMessage('content长度必须在1-2048之间'),
    body('tags')
        .notEmpty().withMessage('tags不能为空')
        .isArray().withMessage('tags必须为数组')
        .custom((value) => {
            if (value.length > 5) {
                throw new Error('tags长度不能超过5个');
            }
            return true;
        }),
    body('status')
        .notEmpty().withMessage('status不能为空')
        .isIn(['draft', 'published', 'deleted']).withMessage('status必须为draft或published或deleted')
];

